﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WCF
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class getData : IWCF
    {
        public PairComposite Add(PairComposite p1, PairComposite p2)
        {
            PairComposite result = new PairComposite();
            result.first = p1.first + p2.first;
            result.second = +p2.second;
            return result;
        }
        public UserComposite GetUser(Guid ID)
        {
            using (UsersEntities db = new UsersEntities())
            {
                try
                {
                    Users user = (from c in db.Users
                                  where c.USERID == ID
                                  select c).Single();
                    UserComposite UserC = new UserComposite();
                    UserC.UserID = user.USERID;
                    UserC.Username = user.AccontName;
                    UserC.Image = user.Image;
                    UserC.Firstname = user.Firstname;
                    UserC.Lastname = user.Lastname;
                    UserC.Gender = user.Gender;
                    UserC.Age = user.Age;
                    UserC.Information = user.Information;

                    return UserC;

                }
                catch
                {
                    return null;

                }

            }
        }
        public bool AddUser(Guid UserID, string Username, string Image, string Firstname, string Lastname, string Gender, int Age, string Information)
        {
            UsersEntities db = new UsersEntities();
            Users user = new Users();
            user.USERID= UserID;
            user.AccontName = Username;
            user.Image = Image;
            user.Firstname = Firstname;
            user.Lastname = Lastname;
            user.Gender = Gender;
            user.Age = Age;
            user.Information = Information;

            db.Users.AddObject(user);

            db.SaveChanges();
            return true;
        }
    }
}
